#!/usr/bin/python
# -*-coding:utf-8-*-
import os
from datetime import datetime

from base.time_schedule import multiprocess_wrap_by_signal
from base.time_schedule import writeToFile
from base.utils import delete_file_list
from copy import deepcopy

from factor_mining_model_v1.hf_trade_factor_mining_v1 import main as hf_trade_factor_mining_v1_main

from dir_info import cache_data_dir

def main(run_number=2):
    start_id = 0

    run_func_dict = {
        # 构建基准数据
        '%s' % id: deepcopy(hf_trade_factor_mining_v1_main) for id in range(start_id, run_number)
    }

    # TODO - 生成计划表
    now_dt = datetime.now().strftime('%Y%m%d%H%S')

    signal_filename = 'zbc_hf_factor_mining_v1' + now_dt

    run_schedule = {i: False if i > start_id else True for i in range(start_id, run_number)}

    run_schedule_file_path = os.path.join(cache_data_dir, signal_filename+'.pkl')

    writeToFile(run_schedule, run_schedule_file_path)

    kwargs = {
        '%s' % id : {'nothing': None} for id in range(start_id, run_number)
    }

    run_schedule_signals_list = list(range(start_id, len(run_func_dict)))

    ####
    # TODO - update main
    multiprocess_wrap_by_signal(run_func_dict=run_func_dict,
                                interaction_file_path=run_schedule_file_path,
                                signal_ids_list=run_schedule_signals_list,
                                is_sleep=True,
                                verbose=False,
                                is_daemon=True,
                                **kwargs)

    return run_schedule_file_path


if __name__ == '__main__':
    run_number = 3

    run_schedule_file_path = main(run_number)

    # TODO - del interaction file
    to_del_file = [run_schedule_file_path]
    delete_file_list(to_del_file)


